#include "CTeleporter.h"
#include "CNode.h"
#include "CPlayer.h"
#include "CCamera.h"
#include "..\\Wrappers\CSGD_Direct3D.h"
#include "..\\Messaging\\CSGP_EventSystem.h"

CTeleporter::CTeleporter()
{
	isOpen = false;
	isNodePlayerOwned = false;
	link = NULL;
}

void CTeleporter::Activate()
{
	// Mark this teleporter as owned by the player
	isNodePlayerOwned = true;

	// Open this and the linked teleporter for transport
	SetIsOpen(true);
	link->SetIsOpen(true);
}

void CTeleporter::DeActivate()
{
	// Unmark this teleporter as owned by the player
	isNodePlayerOwned = false;

	// Check if the linked teleporter is player owned
	if(!link->GetPOwned())
	{// Not player owned
		// Close both teleporters for transport
		SetIsOpen(false);
		link->SetIsOpen(false);
	}
}

void CTeleporter::setLink(CTeleporter* linked)
{
	link = linked;
	link->link = this;
}
void CTeleporter::setNode(CNode* parent)
{
	node = parent;
}

void CTeleporter::Teleport()
{
	if(!GetIsOpen())
		return;
  	CPlayer* player = CPlayer::GetInstance();
	node->ExitNode();
	
	player->SetPosX(link->GetPosX());
	player->SetPosY(link->GetPosY());
	CSGP_EventSystem::GetInstance()->SendEvent("teleport", link->node);
	link->node->EnterNode();
}

void CTeleporter::Render()
{
	
}

